<project name="Global.Core.Targets" default="Core.Info">

	<!-- ${Core.ProjectWebFolder}">-->

  <target name="Core.CleanDeployFolder">
    <echo message="Cleaning ${Global.DeployFolder}" />
    <delete dir="${Global.DeployFolder}" failonerror="false" if="${directory::exists(Global.DeployFolder)}" />
    <mkdir dir="${Global.DeployFolder}" unless="${directory::exists(Global.DeployFolder)}" />
  </target>

  <target name="Core.ZipFilesToDeployFolder">
    
    <echo message="Zip to file: ${Global.WebbFolder}\${Project.FileName}" />
    <echo message="Zip from dir: ${Global.WebbFolder}\${Project.ProjectName}" />

    <zip zipfile="${Global.WebbFolder}\${Project.FileName}">
      <fileset basedir="${Global.WebbFolder}\${Project.ProjectName}" prefix="ParvisWebb">
        <include name="**/*" />
      </fileset>
    </zip>
  </target>
  
  <target name="Core.CopyWebbToDeployFolder">
    <echo message="copy to ${Project.DeployFolder}\${Project.ProjectName}" />
    <echo message="copy from ${Project.ProjectFolder}" />

    <copy todir="${Project.DeployFolder}\${Project.ProjectName}">
			<fileset basedir="${Project.ProjectFolder}\" >
				<include name="**/*" />
				<exclude name="build.xml" />
				<exclude name="properties.include" />
				<exclude name="**/_ReSharper.StockholmsStad.Web.UI/**" />
				<exclude name="User.config" />
				<exclude name="**/*.csproj" />
				<exclude name="**/*.sln" />
        <exclude name="**/*.suo" />
        <exclude name="**/*.user" />
        <exclude name="**/*.cache" />
        <exclude name="**/*.cs" />
        <exclude name="**/obj/**" />
        <exclude name="**/App_Data/**" />
      </fileset>
		</copy>
	</target>

  <target name="Core.CopyTestsToDeployFolder">

    <echo message="copy to ${Project.DeployFolder}" />
    <echo message="copy from ${Project.ProjectFolder}\${Configuration}\" />

    <copy todir="${Project.DeployFolder}">
      <fileset basedir="${Project.ProjectFolder}\${Configuration}\" >
        <include name="**/*.dll" />
        <include name="**/*.config" />
      </fileset>
    </copy>
  </target>

  <target name="Core.CopySetupToDeployFolder">

    <echo message="copy to ${Project.DeployFolder}" />
    <echo message="copy from ${Project.ProjectFolder}\${Configuration}\" />

    <copy todir="${Project.DeployFolder}">
      <fileset basedir="${Project.ProjectFolder}\${Configuration}\" >
        <include name="**/*.msi" />
      </fileset>
    </copy>
  </target>

  <target name="Core.CopyReportsToDeployFolder">

    <echo message="copy to ${Global.ReportFolder}" />
    <echo message="copy from ${Project.ReportFolder}" />

    <copy todir="${Global.ReportFolder}">
      <fileset basedir="${Project.ReportFolder}\" >
        <include name="*.rdl" />
        <include name="*.jpg" />
      </fileset>
    </copy>
  </target>

  <target name="Core.GetLatest">

    <if test="${directory::exists(Global.DBSrcFolder)}">
      <exec program="${SVNEXE}" failonerror="false">
        <arg value="/command:update" />
        <arg value="/path:${Global.DBSrcFolder}\" />
        <arg value="${SVN_DBURL}" />
        <arg value="/closeonend:2" />
      </exec>
    </if>

    <if test="${not directory::exists(Global.DBSrcFolder)}">
      <exec program="${SVNEXE}" failonerror="false">
        <arg value="/command:checkout" />
        <arg value="/path:${Global.RootFolder}\" />
        <arg value="${SVN_DBURL}" />
        <arg value="/closeonend:2" />
      </exec>
    </if>


    <if test="${directory::exists(Global.DocsFolder)}">
      <exec program="${SVNEXE}" failonerror="false">
        <arg value="/command:update" />
        <arg value="/path:${Global.DocsFolder}\" />
        <arg value="${SVN_DOCURL}" />
        <arg value="/closeonend:2" />
      </exec>
    </if>

    <if test="${not directory::exists(Global.DocsFolder)}">
      <exec program="${SVNEXE}" failonerror="false">
        <arg value="/command:checkout" />
        <arg value="/path:${Global.RootFolder}\" />
        <arg value="${SVN_DOCURL}" />
        <arg value="/closeonend:2" />
      </exec>
    </if>

    <if test="${directory::exists(Global.SrcFolder)}">
      <exec program="${SVNEXE}" failonerror="false">
        <arg value="/command:update" />
        <arg value="/path:${Global.SrcFolder}\" />
        <arg value="${SVN_SRCURL}" />
        <arg value="/closeonend:2" />
      </exec>
    </if>

    <if test="${not directory::exists(Global.SrcFolder)}">
      <exec program="${SVNEXE}" failonerror="false">
        <arg value="/command:checkout" />
        <arg value="/path:${Global.RootFolder}\" />
        <arg value="${SVN_SRCURL}" />
        <arg value="/closeonend:2" />
      </exec>
    </if>

  </target>

  <target name="Core.GetDBFilesTrunk">

    <echo message="Get DB files from trunk" />
    
    <if test="${directory::exists(Global.DBSrcFolder)}">
      <exec program="${SVNEXE}" failonerror="false">
        <arg value="/command:update" />
        <arg value="/path:${Global.DBSrcFolder}\" />
        <arg value="${SVN_DBURL_TRUNK}" />
        <arg value="/closeonend:2" />
      </exec>
    </if>

    <if test="${not directory::exists(Global.DBSrcFolder)}">
      <exec program="${SVNEXE}" failonerror="false">
        <arg value="/command:checkout" />
        <arg value="/path:${Global.RootFolder}\" />
        <arg value="${SVN_DBURL_TRUNK}" />
        <arg value="/closeonend:2" />
      </exec>
    </if>
    
  </target>

  <target name="Core.CopyDBScripts">

    <copy todir="${Global.DBDestTablesFolder}\">
      <fileset basedir="${Global.DBSrcScriptFolder}\Create\" >
        <include name="*.Table.sql" />
      </fileset>
    </copy>

    <copy todir="${Global.DBDestViewsFolder}\">
      <fileset basedir="${Global.DBSrcScriptFolder}\Create\" >
        <include name="*.View.sql" />
      </fileset>
    </copy>

    <copy todir="${Global.DBDestProcFolder}\">
      <fileset basedir="${Global.DBSrcScriptFolder}\Create\" >
        <include name="*.StoredProcedure.sql" />
      </fileset>
    </copy>

    <copy todir="${Global.DBDestJobFolder}\">
      <fileset basedir="${Global.DBSrcScriptFolder}\Create\" >
        <include name="*.Job.sql" />
      </fileset>
    </copy>

    <copy todir="${Global.DBDestDataFolder}\">
      <fileset basedir="${Global.DBSrcScriptFolder}\Insert\" >
        <include name="*.sql" />
      </fileset>
    </copy>

    <copy todir="${Global.DBDestUserFolder}\">
      <fileset basedir="${Global.DBSrcScriptFolder}\CreateUser\" >
        <include name="*.sql" />
      </fileset>
    </copy>

    <copy todir="${Global.DBDestScriptFolder}\">
      <fileset basedir="${Global.DBDeploymentScriptFolder}\" >
        <include name="*.cmd" />
      </fileset>
    </copy>

    <copy todir="${Global.DBDestScriptFolder}\">
      <fileset basedir="${Global.DBSrcScriptFolder}\Create\" >
        <include name="createDB.sql" />
        <include name="createTestDB.sql" />
        <include name="alterDB.sql" />
        <include name="alterTestDB.sql" />
        <include name="ParvisIndexes.sql" />
        <include name="ParvisVersion.sql" />
        <include name="StockholmsStad.DataBase.Procedures.SqlAssembly.sql" />
        <include name="StockholmsStad.DataBase.Procedures.SqlAssembly.Test.sql" />
      </fileset>
    </copy>

    <copy todir="${Global.ReportFolder}\">
      <fileset basedir="${Global.ReportScriptFolder}\" >
        <include name="*.cmd" />
        <include name="*.rss" />
      </fileset>
    </copy>
    
  </target>

  <target name="Core.CopyReportScripts">

    <copy todir="${Global.ReportFolder}\">
      <fileset basedir="${Global.ReportScriptFolder}\" >
        <include name="*.cmd" />
        <include name="*.rss" />
      </fileset>
    </copy>

  </target>

</project>